from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

from models import Base

class Course(Base):
    """
        课程信息
    """
    __tablename__ = "course"
    id = Column(Integer,primary_key=True,index=True,comment="课程编号")
    name = Column(String(20),index=True,comment="课程名")
    size = Column(Integer,comment="容量")
    introduction = Column(String(50),comment="简介")
    # sudents:表示course和student多对多关系
    students=relationship("Student",secondary="course_student",back_populates="courses",lazy="dynamic")

class CourseStudent(Base):
    """
        课程-学生关系信息
    """
    __tablename__ = "course_student"
    id=Column(Integer,primary_key=True,autoincrement=True)
    course_id=Column(Integer,ForeignKey('course.id'),primary_key=True)
    student_id=Column(Integer,ForeignKey('student.id'),primary_key=True)
